package com.aaa.controller.sas;

import cn.hutool.json.JSONUtil;
import com.github.pagehelper.Page;
import com.aaa.controller.util.BaseController;
import com.aaa.entity.mht.TblMht;
import com.aaa.entity.util.PageSortEntity;
import com.aaa.entity..QuestionSas;
import com.aaa.entity.util.Result;
import com.aaa.service..SasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/sas")
public class SasController extends BaseController {
    @Autowired
    SasService sasService;

    @RequestMapping("/querySas.do")
    @ResponseBody
    public Result querySas(PageSortEntity page, QuestionSas sas) {
        Page query = sasService.query(page, sas);
        return success(query.getResult(),query.getTotal() );
    }
    @RequestMapping("/querySasbyid.do")
    @ResponseBody
    public Result querySasbyid() {
        return success(sasService.query());
    }



    @RequestMapping("/repetitionName.do")
    @ResponseBody
    public Result repetitionName( QuestionSas sas ) {
        List<QuestionSas> tblMhts = sasService.queryByQuestion(sas);
        if (tblMhts.size()==0){
            return success();
        }else {
            return fail();
        }
    }

    @RequestMapping("/updateSas.do")
    @ResponseBody
    public Result updateSas(QuestionSas sas) {
        if (JSONUtil.isNull(sas.getStatus())){
            sas.setStatus(1);
        }
        System.out.println(sas);
        int update = sasService.update(sas);
        if (update>0){
            return success("操作成功");
        }else {
            return fail("操作失败");
        }
    }


}
